<?php

namespace admin\controllers;

use app\models\Admin;
use admin\components\AdminController;

class UserController extends AdminController {

    public $name = '管理账户';

    public function actionIndex() {
        $wd = $this->get('wd');

        $searchModel = !$this->enableSearch ? NULL : new Admin();
        $query = Admin::find();
        $query->with = ['group'];
        $query->andFilterWhere(['like', 'author', $wd])
            ->orFilterWhere(['like', 'username', $wd]);

        $dataProvider = $this->search($query, $searchModel);
        
        return $this->render(compact('searchModel', 'dataProvider'));
    }


    public function actionSave($id = FALSE) {
        /* @var $model Admin */
        $model = $this->findModel($id, Admin::className());
        $model->setScenario($model->isNewRecord ? 'new' : 'save');

        $checkAccess = $this->checkAccessByGroup(FALSE);
        if (!$model->load($this->post())) {
            return $this->render(compact('model', 'checkAccess'));
        }
        return $model->saveAdmin();
    }

}
